#! /bin/bash
export SQOOP_HOME=/usr/bin/sqoop

if [ $# == 1 ] 
then 
   dateStr=$1
   tableMonth=`date -d $1 +'%Y_%m'`
else 
   dateStr=`date -d '-1 day' +'%Y-%m-%d'`
   tableMonth=`date -d '-1 day' +'%Y_%m'`
fi

echo ${dateStr}

#第一次导入
#分区表
#1,itcast_school==>学校信息表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://hadoop01:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select *,'${dateStr}' as dt from itcast_school where 1=1 and (create_date_time between '1970-01-01 00:00:00' and '${dateStr} 23:59:59') and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table itcast_school \
-m 1 

#2,itcast_subject==>学科表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://hadoop01:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select *,'${dateStr}' as dt from itcast_subject where 1=1 and (create_date_time between '1970-01-01 00:00:00' and '${dateStr} 23:59:59') and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table itcast_subject \
-m 1 


#3,scrm_department==>部门表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://hadoop01:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select *,'${dateStr}' as dt from scrm_department where 1=1 and (create_date_time between '1970-01-01 00:00:00' and '${dateStr} 23:59:59') and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table scrm_department \
-m 1 


#4,employee==>员工表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://hadoop01:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select *,'${dateStr}' as dt from employee where 1=1 and (create_date_time between '1970-01-01 00:00:00' and '${dateStr} 23:59:59') and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table employee \
-m 1 


#5customer==>客户静态信息表,分区表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://hadoop01:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select *, '${dateStr}' as dt from customer where 1=1 and (create_date_time between '1970-01-01 00:00:00' and '${dateStr} 23:59:59') and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table customer \
-m 1 


#6==>customer_appeal,客户投诉信息表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://hadoop01:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select *, '${dateStr}' as dt from customer_appeal where 1=1 and (create_date_time between '1970-01-01 00:00:00' and '${dateStr} 23:59:59') and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table customer_appeal \
-m 1 


#--7==>customer_clue,客户线索表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://hadoop01:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select *, '${dateStr}' as dt from customer_clue where 1=1 and (create_date_time between '1970-01-01 00:00:00' and '${dateStr} 23:59:59') and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table customer_clue \
-m 1 

#8,customer_relationship==>客户意向表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://hadoop01:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select *, '${dateStr}' as dt from customer_relationship where 1=1 and (create_date_time between '1970-01-01 00:00:00' and '${dateStr} 23:59:59') and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table customer_relationship \
-m 1 


#9,itcast_clazz==>报名课程表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://hadoop01:3306/scrm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select *, '${dateStr}' as dt from itcast_clazz where 1=1 and (create_date_time between '1970-01-01 00:00:00' and '${dateStr} 23:59:59') and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table itcast_clazz \
-m 1 



